import * as type from "./mutation"
import shop from "../api/shop"
//计数器
export const increment = ({ commit }) => commit(type.INCREMENT)
export const decrement = ({ commit }) => commit(type.DECREMENT)

//产品
export const getAllProducts = ({ commit }) => {
	shop.getProducts(products => {
		commit(type.RECEIVE_PRODUCTS,{products})
	});
}

export const addToCart = ({commit},product) => {
	if(product.inventory > 0){
		commit(type.ADD_TO_CART,{id:product.id})
	}
}

export const removeFromCart = ({commit},product) => {
	commit(type.REMOVE_FROM_CART,product)
}